Skip to content

feat(core): M1 kernel MVP — DeepSeek provider + 6 P0 tools + agent loop + sessions#1

Merged
oratis merged 1 commit into
mainfrom
feat/m1-kernel-mvp
May 27, 2026
Merged

feat(core): M1 kernel MVP — DeepSeek provider + 6 P0 tools + agent loop + sessions#1
oratis merged 1 commit into
mainfrom
feat/m1-kernel-mvp

Conversation

@oratis

@oratis oratis commented May 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Ships DEVELOPMENT_PLAN.md §6 M1 in full (kernel-only — trust dialog deferred to M2 where the CLI/onboarding surface lives).
  • 6 P0 tools (Read/Write/Edit/Bash/Grep/Glob), DeepSeekProvider with streaming + tool_calls + reasoning_content, jsonl sessions with file snapshots, agent loop tying them together.
  • 62 tests passing (0 failed, 4 skipped on hosts without ripgrep).

Test plan

  • `pnpm typecheck` — green (tsc -b project references)
  • `pnpm build` — all 4 packages emit dist/
  • `pnpm test` — 62 passed / 4 skipped / 0 failed
  • `pnpm format:check` — all files conformant
  • Manual: `node apps/cli/dist/cli.js --version` still works (CLI bin untouched; consumes core in M2)

CI will additionally validate: link-check job (all M0 docs present), lint stub.

Documentation

  • New: `docs/core-api.md` (public surface, examples, storage layout, what M1 does NOT include)
  • New: `docs/milestones/M1.md` (delivery report, design decisions, known gaps)
  • No `DEVELOPMENT_PLAN.md` change needed (M1 scope unchanged from v0.5)

Release notes label

  • `release-notes:feature` — new package surface

Checklist

  • PR title is conventional commits format
  • Commit is conventional commits format
  • Added 62 tests covering all M1 modules
  • CI green — will populate after push completes

Related

Follows: `chore(m0): initial M0 skeleton` (3b39d99) on `main`.
Closes: M1 milestone.

Design decisions called out for review

  1. DeepCode-internal `ContentBlock` types (not Anthropic SDK types). Providers convert at boundary via `anthropicShapeToOpenAI()`. Avoids hard SDK dependency.

  2. History snapshotted per provider call — `messages: [...history]` instead of `messages: history`. Prevents subsequent-turn mutations from leaking into earlier calls' provider record. Caught by test, fixed in M1.

  3. `apiKey || authToken` not `??` — empty string isn't nullish; `??` left empty apiKey through. Caught by test.

  4. Bash `run_in_background` deliberate stub — returns error pointing to M3.15.3. Defers entire background-task infrastructure to where its design lives (TaskCreate/Monitor).

  5. Snapshot blob storage colocated with sessions — `//snapshots/{NNNNN-ts-hash.blob, manifest.jsonl}`. Same storage that §3.15.9 rewind UX will read in M7.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

…op + sessions

Implements DEVELOPMENT_PLAN.md §6 M1 in full (except trust dialog, deferred to
M2 where the CLI/onboarding surface lives — kernel exposes the session/snapshot
primitives that M2 will consume).

What ships
----------
- DeepSeekProvider (packages/core/src/providers/deepseek.ts)
  - OpenAI-compatible streaming via injected `fetch`
  - Handles `content`, `reasoning_content`, `tool_calls` deltas
  - Dual credential (apiKey X-Api-Key OR authToken Bearer)
  - DEEPSEEK_MODELS and EFFORT_PARAMS enforce 8192 max_tokens hard limit
  - anthropicShapeToOpenAI boundary converter (StoredMessage[] ↔ chat.completions)
- 6 P0 tools (packages/core/src/tools/{read,write,edit,bash,grep,glob}.ts)
  - Read: numbered lines + offset/limit + line-width truncation
  - Write: creates parent dirs
  - Edit: exact-string replacement, fails on non-unique unless replace_all
  - Bash: spawn /bin/sh -c, timeout, stdout/stderr capture, 30KB cap each
  - Grep: ripgrep via execFile, graceful (no matches) handling
  - Glob: built-in fs.glob (Node 22+), mtime-desc sort
  - ToolRegistry + BUILTIN_TOOLS for one-line wire-up
- Sessions (packages/core/src/sessions/)
  - jsonl message log + .meta.json sidecar
  - Snapshots (sha256-keyed blobs + manifest.jsonl) — pre/post Edit/Write
  - SessionManager facade (create / load / list / append / snapshot)
- Agent loop (packages/core/src/agent.ts)
  - provider ↔ tools ↔ session orchestration
  - history-snapshotting per turn (provider sees stable input)
  - automatic snapshot on Edit/Write tool calls
  - AbortSignal-aware, maxTurns cap, comprehensive AgentEvent stream

Tests (62 passed, 4 skipped, 0 failed in ~1.3s)
-----------------------------------------------
- providers/deepseek.test.ts (13) — streaming text / reasoning_content / tool calls /
  msg-shape conversion / auth variants / model invariants
- tools/{read,write,edit,bash,grep,glob}.test.ts (31 tests) — real fs / real exec
- sessions/{storage,snapshots}.test.ts (11) — round-trip, manifest, restore
- agent.test.ts (7) — end_turn / tool dispatch / unknown tool / maxTurns /
  abort / session+snapshots / multi-turn history feedback

Mock strategy: MockProvider for agent tests (deterministic), mockFetch returning
SSE chunks for provider tests. Zero new test deps.

Docs
----
- docs/core-api.md — full public API surface + storage layout + what M1 doesn't
- docs/milestones/M1.md — milestone postmortem, design decisions, known gaps

Verified
--------
  pnpm typecheck   → green
  pnpm build       → all packages emit dist/
  pnpm test        → 62 passed / 4 skipped (ripgrep-dependent) / 0 failed
  pnpm format:check → all conformant

Bugs found and fixed in-flight
------------------------------
- `apiKey ?? authToken` failed for `apiKey: ''` (nullish only) — switched to `||`
- `messages: history` passed by reference let later turns mutate earlier calls' record
  → `messages: [...history]` snapshot per call

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@oratis oratis merged commit b58fc71 into main May 27, 2026
1 of 2 checks passed
@oratis oratis deleted the feat/m1-kernel-mvp branch May 27, 2026 16:09
oratis added a commit that referenced this pull request May 27, 2026
Implements docs/design/sandbox-plan-worktree.md §5.1 decision flow.

Shipped
-------
- harness/tool-dispatcher.ts (105 lines)
  · dispatchToolCall() combines:
    1. evaluatePermission (existing M2)
    2. evaluateMode      (existing M3a)
    3. PreToolUse hook   (existing M3a HookDispatcher)
  · Returns DispatchVerdict { decision, source, reason, hook?, ... }
  · plan-blocked short-circuits before hooks (matches invariant #1)
  · Hook JSON output decision=deny/ask overrides mode allow
  · Hook non-zero exit code → deny

- agent.ts integration:
  · New RunAgentOptions fields: mode, permissions, hooks, approval
  · Tool-call loop now consults dispatcher when mode is set
  · 'ask' verdict invokes ApprovalCallback (caller-supplied)
  · 'deny' / 'plan-blocked' produce tool_result with is_error=true,
    fed back to LLM so it can recover
  · PostToolUse hook fires after every tool execution
  · Backwards compatible: when mode is unset, M1 behavior (allow all)

Tests
-----
- harness/tool-dispatcher.test.ts (9 tests)
  All paths of the §5.1 decision tree, including plan short-circuit,
  acceptEdits with permission-deny still winning, hook JSON override,
  hook non-zero exit, dontAsk strict deny.

Total: 206 passed / 4 skipped / 0 failed (was 197).

Deferred to M3c
---------------
MCP client / compaction / statusLine / /init multi-phase / auto-classifier
mode / hook handler types beyond `command` / hook `if` field.

CLI REPL not yet plumbed with mode (M3c). Mode-aware gating only activates
when a caller passes `mode:` to `runAgent` — current REPL still uses M1
path.

Verified
--------
  pnpm typecheck   → green
  pnpm test        → 206 passed / 4 skipped
  pnpm format:check → conformant

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
oratis added a commit that referenced this pull request May 28, 2026
This session ("继续推进" from v2) added 5 PRs on top of #1-#16:
  · #17 M3c-rest tools (TodoWrite + WebFetch + WebSearch)
  · #18 M3.5 attack tests + security-model.md
  · #19 M8 headless mode (-p / --print)
  · #20 M5.2 plugin live wire-up
  · #21 system-reminder injector

Test count: 313 → 387 (+74).
Scope completion estimate: 65-70% → 72-78%.

Major remaining items: M6 Mac Electron (still 0%), M7 file panel (depends
on M6), and the M3c-rest/M8/M5.2 leftovers itemized in the body.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant